<?php
/**
 * 在线音乐类，管理合作方音乐来源
 * @author "i@huanglixiang.com"
 *
 */

class MT_Music {

    private $default_platform = 'kuwo';
    private $current_platform = '';
    private $suport_platforms = array(
        'kuwo',
    );
    private $platform_objects = array(); //用于存放各音乐平台的对象 
    
    function __construct(){
        $this->setCurrentPlatform($this->current_platform);
    }
    
    function setCurrentPlatform($platform){
        
        if(!in_array($platform, $this->suport_platforms)){
            $this->current_platform = $this->default_platform; //给个默认的，防止报错
        }else{
            $this->current_platform = $platform;
        }
        
        //创建对象
        if(empty($this->platform_objects[$this->current_platform])){
            include_once 'Music/MusicBase.php';
            include_once 'Music/'.ucfirst($this->current_platform).'.php';
            $this->platform_objects[$this->current_platform] = new Music\kuwo();
        }
    }
    
    function getCurrentPlatform(){
        return $this->current_platform;
    }
    
    function getPlatformObject(){
        return $this->platform_objects[$this->current_platform];
    }
    
    function getArtistList($keyword , $page , $count){
        $result = $this->getPlatformObject()->getArtistList($keyword , $page , $count);
        return $result;
    }
    
    function getSongList($keyword , $page , $count){
        $result = $this->getPlatformObject()->getSongList($keyword , $page , $count);
        return $result;
    }
    
    function getSongUrl($song_id , $file_ext='mp3'){
        $result = $this->getPlatformObject()->getSongUrl($song_id, $file_ext);
        return $result;
    }
}
    